package br.com.imob.modelo;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Gilton Nascimento
 */
@Entity
@Table(name = "\"LOGIN\"", catalog = "imob", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Login.findAll", query = "SELECT l FROM Login l"),
    @NamedQuery(name = "Login.findByLoginId", query = "SELECT l FROM Login l WHERE l.loginId = :loginId"),
    
    @NamedQuery(name = "Login.findByLogin", query = "SELECT l FROM Login l WHERE l.login = :login"),
    @NamedQuery(name = "Login.findLikeByLogin", query = "SELECT l FROM Login l WHERE l.login Like :login"),
    
    @NamedQuery(name = "Login.findBySenha", query = "SELECT l FROM Login l WHERE l.senha = :senha"),
    
    @NamedQuery(name = "Login.findByEmail", query = "SELECT l FROM Login l WHERE l.email = :email"),
    @NamedQuery(name = "Login.findLikeByEmail", query = "SELECT l FROM Login l WHERE l.email Like :email"),
    
    @NamedQuery(name = "Login.findBySite", query = "SELECT l FROM Login l WHERE l.site = :site"),
    @NamedQuery(name = "Login.findLikeBySite", query = "SELECT l FROM Login l WHERE l.site Like :site")
    })
public class Login implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
//  <editor-fold defaultstate="collapsed" desc="Geradores de Sequencias">
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
    @SequenceGenerator(name = "SEQ_STORE", sequenceName = "next_login")// </editor-fold>
    @Basic(optional = false)
    @Column(name = "login_id", nullable = false)
    private Integer loginId;
    @Column(name = "login", length = 12)
    private String login;
    @Basic(optional = false)
    @Column(name = "senha", nullable = false, length = 12)
    private String senha;
    @Basic(optional = false)
    @Column(name = "email", nullable = false, length = 150)
    private String email;
    @Column(name = "site", length = 200)
    private String site;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "login", fetch = FetchType.LAZY)
    private List<Empresa> empresaList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "login", fetch = FetchType.LAZY)
    private List<Pessoa> pessoaList;

    public Login() { }

    public Login(Integer id) { loginId = id; }
    public Login(String log) { login= log; }
    
    public Login(int id, String log) { 
    	loginId = id;
    	login= log; 
	}
    
    public Login(Integer id, String log, String psw) { 
    	this(id,log);
    	senha = psw;
    }
    
    public Login(Integer id, String log, String psw, String mail, String sit) { 
    	this(id,log, psw);
    	email = mail;
    	site = sit;
    }
    
    public Login(String tipStr, String arg) {
        if( "login".equalsIgnoreCase(tipStr) )
        	login = arg;
        if( "senha".equalsIgnoreCase(tipStr) )
        	senha = arg;
        if( "email".equalsIgnoreCase(tipStr) )
        	email = arg;
        if( "site".equalsIgnoreCase(tipStr) )
        	site = arg;
    }
    
    public Login(int id, String tipStr, String arg) {
    	this(tipStr, arg);
    	loginId = id;
    }
    
    public Integer getLoginId() {
        return loginId;
    }

    public void setLoginId(Integer loginId) {
        this.loginId = loginId;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public List<Empresa> getEmpresaList() {
        return empresaList;
    }

    public void setEmpresaList(List<Empresa> empresaList) {
        this.empresaList = empresaList;
    }

    public List<Pessoa> getPessoaList() {
        return pessoaList;
    }

    public void setPessoaList(List<Pessoa> pessoaList) {
        this.pessoaList = pessoaList;
    }
    
    public Object[] getValues() {
    	Object[] values = {loginId, login, senha, email, site};
    	return values;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (loginId != null ? loginId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Login)) {
            return false;
        }
        Login other = (Login) object;
        if ((this.loginId == null && other.loginId != null) || (this.loginId != null && !this.loginId.equals(other.loginId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.imob.modelo.Login[loginId=" + loginId + "]";
    }

}